<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/12 0012
 * Time: 14:23
 */

namespace common\models\AgentInfo;


use common\components\DataHelper;
use common\models\Admin\Admin;
use common\models\RegionManagerInfo\RegionManagerInfo;

class AgentInfo extends AgentInfoBase
{
    public static function getDefAgentUid()
    {
        return 2;
    }

    public function rules()
    {
        return array_merge(parent::rules(), [
            ["ali_account", "match", "pattern" => DataHelper::patternMobile(), "message" => "不是一个手机号"],
            ["name", "match", "pattern" => '/^[\x7f-\xff]+$/', "message" => "名称必须是汉字"],
        ]); // TODO: Change the autogenerated stub
    }

    public function isTop()
    {
        return $this->parent_agent == 0;
    }

    public function getAccountInfo()
    {
        return $this->hasOne(Admin::class, [
            "id" => "uid"
        ]);
    }

    public function getManager()
    {
        return $this->hasOne(Admin::class, [
            "id" => "parent_manager"
        ]);
    }

    public function getManagerInfo()
    {
        return $this->hasOne(RegionManagerInfo::class, [
            "uid" => "parent_manager"
        ]);
    }

    public function getParentAgent()
    {
        return $this->hasOne(Admin::class, [
            "id" => "parent_agent"
        ]);
    }
    public function getParentAgentInfo()
    {
        return $this->hasOne(AgentInfo::class, [
            "uid" => "parent_agent"
        ]);
    }
}